package com.milk.base;

import android.app.Application;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

/**
 * Created by oceanzhang on 16/2/17.
 */
public class BaseApplication extends Application implements ApplicationSwitchMonitor{
    private ActivityLifecycleCallbacksWrapper activityLifecycleCallbacksWrapper;
    private boolean isBackground;
    @Override
    public void onCreate() {
        super.onCreate();
        activityLifecycleCallbacksWrapper = new ActivityLifecycleCallbacksWrapper();
        registerActivityLifecycleCallbacks(activityLifecycleCallbacksWrapper);
        activityLifecycleCallbacksWrapper.addApplicationSwitchMonitor(this);
        init();
    }
    protected void init(){
        //image loader init
        ImageLoaderConfiguration configuration = ImageLoaderConfiguration
                .createDefault(this);
        ImageLoader.getInstance().init(configuration);
//        Fresco.initialize(this);
    }

    @Override
    public void applicationEnterForeground() {
        isBackground = false;
    }

    @Override
    public void applicationEnterBackground() {
        isBackground = true;
    }
    public boolean isBackground(){
        return isBackground;
    }

    public static class Message{
        public int code;
        public String msg;
        public Object obj;

        public Message(int code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public Message(int code, String msg, Object obj) {
            this.code = code;
            this.msg = msg;
            this.obj = obj;
        }
    }
}
